/*
 * 1489. 链表化数组
 * 将一个数组变成链表
 * https://www.lintcode.com/problem/convert-array-list-to-linked-list/description
 * 
 * 样例
 * 给出 [1,2,3,4], 返回 1->2->3->4->null
 * 
 * 2018.06.10 @jeyming
 */
package convert_array_list_to_linked_list_1489;

import java.util.ArrayList;
import java.util.List;

//Definition for ListNode.
class ListNode {
	int val;
	ListNode next;
	ListNode(int val) {
		this.val = val;
		this.next = null;     
	}
}

public class Convert_array_list_to_linked_list_1489 {
	
	public static ListNode toLinkedList(List<Integer> nums) {
        // write your code here
		ListNode head = null;
		ListNode p = null;
		ListNode q = null;
		for(int i = 0; i < nums.size(); ++i) {
			p = new ListNode(nums.get(i));
			if(i == 0) {
				head = p;
				q = p;
			} else {
				q.next = p;
				q = p;
			}
		}
//		p = head;
//		while(p != null) {
//			System.out.println(p.val);
//			p = p.next;
//		}
		return head;
    }

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		List<Integer> list = new ArrayList<Integer>();
		list.add(1);
		list.add(2);
		list.add(3);
		list.add(4);
		list.add(5);
		list.add(6);
		list.add(7);
		toLinkedList(list);
	}

}
